//
//  VocherViewModel.m
//  meiyinxiang
//
//  Created by 媒印象 on 27/11/2017.
//  Copyright © 2017 hbjApple. All rights reserved.
//9*
/*
 @property (nonatomic,strong) NSString *condition;//条件
 @property (nonatomic,strong) NSString *vocherid;//券id
 @property (nonatomic,strong) NSString *is_pick;//是否被领取
 @property (nonatomic,strong) NSString *num;//金额
 @property (nonatomic,strong) NSString *pid;
 @property (nonatomic,strong) NSString *status;//
 @property (nonatomic,strong) NSString *tid;
 @property (nonatomic,strong) NSString *title;
 @property (nonatomic,strong) NSString *useless;//是否可用
 @property (nonatomic,strong) NSString *uselesstime;//过期日期
*/

#import "VocherViewModel.h"

@implementation VocherViewModel
- (id)initWithVocherModel:(VocherModel *)vocherModel{
    self.condition = vocherModel.condition;
    self.condition2 = vocherModel.condition2;
    self.vocherid = vocherModel.vocherid;
    self.is_pick = vocherModel.is_pick;
    self.num = vocherModel.num;
    self.pid = vocherModel.pid;
    self.status = vocherModel.status;
    self.tid = vocherModel.tid;
    self.title = vocherModel.title;
    self.is_add = vocherModel.is_add;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:vocherModel.use_end_time.integerValue];
    // NSString *dateString  = [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterLongStyle];
    NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
    
    //设定时间格式,这里可以设置成自己需要的格式
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString*currentDateStr = [dateFormatter stringFromDate:date];
    self.uselesstime = currentDateStr;
    
    return self;
}
@end

@implementation VocherListViewModel
- (void)loadDataWithCompletion:(finishBlock)completion{
    if (self.vocherModels == nil) {
        self.vocherModels = [NSMutableArray array];
    }
    [[MYXHttpManager shared] getVochersListWithResult:^(BOOL success, NSString *msg, NSArray *arrays) {
        if (success) {
            for (VocherModel *model  in arrays) {
                VocherViewModel *viewModel = [[VocherViewModel alloc] initWithVocherModel:model];
                [self.vocherModels addObject:viewModel];
            }
           // self.vocherModels = [NSMutableArray arrayWithArray:arrays];
            completion(YES);
        }else{
            completion(NO);
        }
    } errorResult:^(NSError *enginerError) {
        completion(NO);
    }];
}
@end
